<template>
  <div class="root">
    <div class="divBox">
      <div class="content-container">
        <div class="container">
          <el-row>
            <el-col :span="6">
              <div class="selectbox-root">
                <span class="selectbox-hint" style="min-width: 80px"
                  >核证标准</span
                >
                <div class="selectbox-deliver" />
                <el-cascader
                  style="width: 120px"
                  placeholder="全部"
                  class="selectbox-input"
                  v-model="selectedCertification"
                  :options="Certification"
                  clearable
                  @change="onClickSearch"
                >
                </el-cascader>
              </div>
            </el-col>
            <el-col :span="6">
              <div style="margin-left: 16px" class="selectbox-root">
                <span class="selectbox-hint" style="min-width: 60px">领域</span>
                <div class="selectbox-deliver" />
                <el-cascader
                  placeholder="全部"
                  class="selectbox-input"
                  v-model="selectedField"
                  :options="fieldCodeList"
                  clearable
                  @change="onClickSearch"
                >
                </el-cascader>
              </div>
            </el-col>
            <el-col :span="6">
              <div style="margin-left: 16px" class="selectbox-root">
                <span class="selectbox-hint" style="min-width: 60px">行业</span>
                <div class="selectbox-deliver" />
                <el-cascader
                  placeholder="全部"
                  class="selectbox-input"
                  v-model="selectedIndustry"
                  :options="IndustryList"
                  clearable
                  @change="onClickSearch"
                >
                </el-cascader>
              </div>
            </el-col>
            <el-col :span="6">
              <div style="margin-left: 16px" class="selectbox-root">
                <span class="selectbox-hint" style="min-width: 60px">状态</span>
                <div class="selectbox-deliver" />
                <el-cascader
                  placeholder="全部"
                  class="selectbox-input"
                  v-model="selectedStatus"
                  :options="optionsOnlines"
                  clearable
                  @change="onClickSearch"
                >
                </el-cascader>
              </div>
            </el-col>
          </el-row>
        </div>
        <div style="display: flex">
          <div
            style="margin: 10px 10px 10px 0px; min-width: 600px"
            class="selectbox-root"
          >
            <span class="selectbox-hint" style="min-width: 100px"
              >方法学搜索</span
            >
            <div class="selectbox-deliver" />
            <el-input
              v-model="searchKeyWord"
              placeholder=""
              clearable
              size="medium"
              @keyup.enter.native="onClickSearch"
              @clear="onClickSearch"
            />
          </div>
          <button class="light-green-btn" @click="onClickSearch">查询</button>
        </div>
         <div>
           <button style="margin-top: 0px; margin-bottom: 20px; width: 103px" class="normal-white-btn" @click="onclickAdd">+添加方法学</button>
           <button style="margin-top: 0px; margin-bottom: 20px; margin-left: 10px; width: 120px" class="light-green-btn" @click="onclickSync">同步到ES</button>
          <el-table
            :header-cell-style="{
              background: '#F2F5F7',
              border: '0px solid #DDDDDD',
              color: '#242B35',
              height: '64px',
            }"
            :show-header="true"
            :data="list"
            :row-style="{ height: '64px' }"
            :cell-style="cellStyle"
            stripe
            style="width: 100%; cursor: default"
          >
            <!-- <el-table-column min-width="40" label="" align="center" width="40">
              <template slot="header" slot-scope="{ column }">
                <el-checkbox
                  v-model="column.checked"
                  :indeterminate="indeterminateFlag"
                  :checked="allchecked"
                  label=""
                  @change="updateAllSelected"
                ></el-checkbox>
              </template>
              <template slot-scope="scope">
                <el-checkbox
                  @change="signCheckChange"
                  v-model="scope.row.checked"
                ></el-checkbox>
              </template>
            </el-table-column> -->
            <el-table-column min-width="20"></el-table-column>
            <el-table-column
              label="编号"
              align="left"
              prop="methodCode"
              min-width="60"
            >
            </el-table-column>
            <el-table-column
              :show-overflow-tooltip="true"
              prop="name"
              label="名称"
              align="left"
              min-width="230"
            />
            <el-table-column
              :show-overflow-tooltip="true"
              prop="fieldCodeName"
              label="领域"
              align="left"
              min-width="140"
            />
            <el-table-column
              align="left"
              prop="industryCodeName"
              label="行业"
              min-width="80"
            />
            <el-table-column
              align="left"
              prop="certificationCriteriaName"
              label="核证标准"
              min-width="80"
            />
            <el-table-column
              align="left"
              prop="statusName"
              label="状态"
              min-width="60"
            />
            <el-table-column label="操作" min-width="150" align="center">
              <template slot-scope="scope">
                <a
                  class="list-blue-text"
                  @click="goMethod(scope.row.sourceFileUrl)"
                  >查看</a
                >
                <!-- :class="editStyleChange(scope.row.status)" -->
                <a
                  class="list-green-text"
                  style="margin-left: 10px"
                  @click="onEdit(scope.row)"
                  >编辑</a
                >
                <a
                  style="margin-left: 10px"
                  :class="publishStyleChange(scope.row.statusCode)"
                  @click="onClickPublish(scope.row.id)"
                  >发布</a
                >
                <a
                  style="margin-left: 10px"
                  @click="onClickOffline(scope.row.id)"
                  :class="offlineStyleChange(scope.row.statusCode)"
                  >下线</a
                >
                <a
                  style="margin-left: 10px; color: #f56c6c; cursor: pointer;"
                  @click="onClickDelete(scope.row.id)"
                  >删除</a
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div style="margin-top: 30px; margin-bottom: 10px" class="pageBox">
        <div style="flex-grow: 1" />
        <span style="margin: auto" class="pageBox-total-num"
          >共{{ total }}条</span
        >
        <el-pagination
          style="margin: auto"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="current"
          :page-size="pageSize"
          :page-count="pageCount"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
       <!-- 添加方法学 -->
      <el-dialog :title="dialogText" :visible.sync="addMethodFormVisible" width="40%">
        <el-row>
          <el-col :span="5"><span class="table-text">方法学编号:<span style="color: red">*</span></span></el-col>
          <el-col :span="19">
            <el-input v-model="methodForm.methodCode" placeholder="请输入方法学编号" autocomplete="off" size="medium"></el-input>
          </el-col>
          <div style="clear: both; height: 20px"></div>
          <el-col :span="5"><span class="table-text">方法学字典码:<span style="color: red">*</span></span></el-col>
          <el-col :span="19">
            <el-input v-model="methodForm.dictCode" placeholder="请输入方法学字典码" autocomplete="off" size="medium"></el-input>
          </el-col>
          <div style="clear: both; height: 20px"></div>
          <el-col :span="5"><span class="table-text">方法学名称:<span style="color: red">*</span></span></el-col>
          <el-col :span="19">
            <el-input v-model="methodForm.name"  placeholder="请输入方法学名称" autocomplete="off" size="medium"></el-input>
          </el-col>
          <div style="clear: both; height: 20px"></div>
          <el-col :span="5"><span class="table-text">领域:<span style="color: red">*</span></span></el-col>
          <el-col :span="19">
            <el-select v-model="methodForm.fieldCode" placeholder="请选择领域" size="medium" style="width: 100%">
                <el-option v-for="(item, index) in fieldCodeList" :key="index" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-col>
          <div style="clear: both; height: 20px"></div>
          <el-col :span="5"><span class="table-text">行业:</span></el-col>
          <el-col :span="19">
            <el-select v-model="methodForm.industryCode" placeholder="请选择行业" size="medium" style="width: 100%">
                <el-option v-for="(item, index) in IndustryList" :key="index" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-col>
          <div style="clear: both; height: 20px"></div>
          <el-col :span="5"><span class="table-text">类型:</span></el-col>
          <el-col :span="19">
              <el-select v-model="methodForm.fieldChildType" placeholder="请选择类型" size="medium" style="width: 100%">
                <el-option v-for="(item, index) in fieldChildCodeList" :key="index" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-col>
          <div style="clear: both; height: 20px"></div>
          <el-col :span="5"><span class="table-text">核证标准:<span style="color: red">*</span></span></el-col>
          <el-col :span="19">
            <el-select v-model="methodForm.certificationCriteria" placeholder="请选择核证标准" size="medium" style="width: 100%">
                <el-option v-for="(item, index) in Certification" :key="index" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-col>
          <div style="clear: both; height: 20px"></div>
          <el-col :span="5"><span class="table-text">pdf文档url:<span style="color: red">*</span></span></el-col>
          <el-col :span="19">
            <el-input v-model="methodForm.sourceFileUrl" placeholder="请输入pdf文档url" autocomplete="off" size="medium"></el-input>
          </el-col>
        </el-row>
        <div style="clear: both; height: 20px"></div>
          <el-col :span="5"><span class="table-text">world文档url:</span></el-col>
          <el-col :span="19">
            <el-input v-model="methodForm.wordUrl" placeholder="请输入world文档url"  autocomplete="off" size="medium"></el-input>
          </el-col>
        <div slot="footer" class="dialog-footer" align="rigth">
          <el-button @click="onCancel">取 消</el-button>
          <el-button @click="saveMothod" type="primary">保存</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import { getEscarbonMethodologyByKeyword,addCarbonMethodology,updateCarbonMethodology,synContentCarbonMethodology,deleteMethod } from "@/api/carbonAssetApi";
import { editMethod } from "@/api/carbonAssetApi";
import selectDropDownBox from "@/components/selectbox/selectDropDownBox.vue";
import { openUrlInNewWindow } from "@/libs/OpenHelper";
import { getCertificationCriteriaDict, getBusinessDict, getMethodStatusDict, getProjectAreaDict, getProjectTypeDict, getAllDictGroupedData } from "@/config/dictHelper";
import { cursor } from "@/libs/element-table";
export default {
  name: "companyPackage",
  components: { selectDropDownBox },
  data() {
    return {
      indeterminateFlag: false, //表头复选框状态
      reRender: true, // 重新渲染列表使用
      allchecked: false,
      searchKeyWord: "",
      selectedCertification: "", //被选中的标准
      selectedIndustry: "", //被选中的行业
      selectedStatus: "", //被选中的状态
      fieldCodeList: [], //领域字典
      selectedField: "", //领域
      list: [],
      total: 0,
      current: 0,
      pageCount: 1,
      pageSize: 10,
      Certification: [], //核证标准字典
      IndustryList: [], //行业字典
      methodUrl:
        "https://carbonmsger.feishu.cn/drive/folder/fldcnaUxGTDbmMBqgOuMUkD5Pxh",
      optionsOnlines: [],
      value: "",
      /* 添加方法学 */
      fieldChildCodeList: [],//项目类型
      addMethodFormVisible:false,
      dialogText:"添加方法学",//
      methodForm:{
        id:"",
        dictCode:"",
        fieldCode:'',//领域
        certificationCriteria:'',//	核证标准（字典：007）
        industryCode:'',//	行业编码（字典：002）
        methodCode:'',//	方法学编码
        name:'',//	方法学名称
        pdfUrl:"",//	飞书pdf路径
        wordUrl:'',//	飞书word路径
        fieldChildType:"",//项目类型
        sourceFileUrl:"",////	飞书pdf路径
      },
      // 模拟数据存储
      mockData: [],
      nextId: 1
    };
  },
  methods: {
    // 初始化模拟数据
    initMockData() {
      console.log('初始化模拟数据...');
      
      // 模拟字典数据
      this.Certification = [
        { label: "全部" },
        { label: "VCS", value: "VCS" },
        { label: "CDM", value: "CDM" },
        { label: "GS", value: "GS" },
        { label: "CCER", value: "CCER" }
      ];
      
      this.IndustryList = [
        { label: "全部" },
        { label: "能源", value: "ENERGY" },
        { label: "制造业", value: "MANUFACTURING" },
        { label: "建筑业", value: "CONSTRUCTION" },
        { label: "交通运输", value: "TRANSPORTATION" },
        { label: "农业", value: "AGRICULTURE" },
        { label: "废物管理", value: "WASTE_MANAGEMENT" },
        { label: "林业", value: "FORESTRY" }
      ];
      
      this.fieldCodeList = [
        { label: "全部" },
        { label: "可再生能源", value: "RENEWABLE" },
        { label: "能效提升", value: "EFFICIENCY" },
        { label: "碳汇", value: "CARBON_SINK" },
        { label: "甲烷减排", value: "METHANE" },
        { label: "工业过程", value: "INDUSTRIAL" },
        { label: "建筑节能", value: "BUILDING" },
        { label: "废物处理", value: "WASTE" },
        { label: "森林碳汇", value: "FOREST" },
        { label: "交通减排", value: "TRANSPORT" },
        { label: "农业减排", value: "AGRICULTURE" }
      ];
      
      this.optionsOnlines = [
        { label: "全部" },
        { label: "未发布", value: "0450000001" },
        { label: "已发布", value: "0450000002" },
        { label: "已下线", value: "0450000003" }
      ];
      
      this.fieldChildCodeList = [
        { label: "全部" },
        { label: "光伏发电", value: "SOLAR" },
        { label: "风力发电", value: "WIND" },
        { label: "水力发电", value: "HYDRO" },
        { label: "生物质能", value: "BIOMASS" }
      ];
      
      // 模拟方法学数据
      this.mockData = [
        {
          id: 1,
          methodCode: "VCS-001",
          dictCode: "VCS001",
          name: "可再生能源发电项目方法学",
          fieldCode: "RENEWABLE",
          fieldCodeName: "可再生能源",
          industryCode: "ENERGY",
          industryCodeName: "能源",
          certificationCriteria: "VCS",
          certificationCriteriaName: "VCS",
          statusCode: "0450000002",
          statusName: "已发布",
          sourceFileUrl: "https://example.com/vcs-001.pdf",
          pdfUrl: "https://example.com/vcs-001.pdf",
          wordUrl: "https://example.com/vcs-001.docx",
          fieldChildType: "SOLAR",
          createdTime: "2024-01-15 10:30:00"
        },
        {
          id: 2,
          methodCode: "CDM-002",
          dictCode: "CDM002",
          name: "能效提升项目方法学",
          fieldCode: "EFFICIENCY",
          fieldCodeName: "能效提升",
          industryCode: "MANUFACTURING",
          industryCodeName: "制造业",
          certificationCriteria: "CDM",
          certificationCriteriaName: "CDM",
          statusCode: "0450000001",
          statusName: "未发布",
          sourceFileUrl: "https://example.com/cdm-002.pdf",
          pdfUrl: "https://example.com/cdm-002.pdf",
          wordUrl: "https://example.com/cdm-002.docx",
          fieldChildType: "WIND",
          createdTime: "2024-01-20 14:20:00"
        },
        {
          id: 3,
          methodCode: "GS-003",
          dictCode: "GS003",
          name: "碳汇造林项目方法学",
          fieldCode: "CARBON_SINK",
          fieldCodeName: "碳汇",
          industryCode: "AGRICULTURE",
          industryCodeName: "农业",
          certificationCriteria: "GS",
          certificationCriteriaName: "GS",
          statusCode: "0450000002",
          statusName: "已发布",
          sourceFileUrl: "https://example.com/gs-003.pdf",
          pdfUrl: "https://example.com/gs-003.pdf",
          wordUrl: "https://example.com/gs-003.docx",
          fieldChildType: "BIOMASS",
          createdTime: "2024-01-25 09:15:00"
        },
        {
          id: 4,
          methodCode: "CCER-004",
          dictCode: "CCER004",
          name: "甲烷减排项目方法学",
          fieldCode: "METHANE",
          fieldCodeName: "甲烷减排",
          industryCode: "ENERGY",
          industryCodeName: "能源",
          certificationCriteria: "CCER",
          certificationCriteriaName: "CCER",
          statusCode: "0450000003",
          statusName: "已下线",
          sourceFileUrl: "https://example.com/ccer-004.pdf",
          pdfUrl: "https://example.com/ccer-004.pdf",
          wordUrl: "https://example.com/ccer-004.docx",
          fieldChildType: "HYDRO",
          createdTime: "2024-01-30 16:45:00"
        },
        {
          id: 5,
          methodCode: "VCS-005",
          dictCode: "VCS005",
          name: "工业过程减排方法学",
          fieldCode: "INDUSTRIAL",
          fieldCodeName: "工业过程",
          industryCode: "MANUFACTURING",
          industryCodeName: "制造业",
          certificationCriteria: "VCS",
          certificationCriteriaName: "VCS",
          statusCode: "0450000001",
          statusName: "未发布",
          sourceFileUrl: "https://example.com/vcs-005.pdf",
          pdfUrl: "https://example.com/vcs-005.pdf",
          wordUrl: "https://example.com/vcs-005.docx",
          fieldChildType: "SOLAR",
          createdTime: "2024-02-01 11:30:00"
        },
        {
          id: 6,
          methodCode: "CDM-006",
          dictCode: "CDM006",
          name: "建筑节能改造方法学",
          fieldCode: "BUILDING",
          fieldCodeName: "建筑节能",
          industryCode: "CONSTRUCTION",
          industryCodeName: "建筑业",
          certificationCriteria: "CDM",
          certificationCriteriaName: "CDM",
          statusCode: "0450000002",
          statusName: "已发布",
          sourceFileUrl: "https://example.com/cdm-006.pdf",
          pdfUrl: "https://example.com/cdm-006.pdf",
          wordUrl: "https://example.com/cdm-006.docx",
          fieldChildType: "WIND",
          createdTime: "2024-02-05 08:20:00"
        },
        {
          id: 7,
          methodCode: "GS-007",
          dictCode: "GS007",
          name: "垃圾填埋气回收方法学",
          fieldCode: "WASTE",
          fieldCodeName: "废物处理",
          industryCode: "WASTE_MANAGEMENT",
          industryCodeName: "废物管理",
          certificationCriteria: "GS",
          certificationCriteriaName: "GS",
          statusCode: "0450000001",
          statusName: "未发布",
          sourceFileUrl: "https://example.com/gs-007.pdf",
          pdfUrl: "https://example.com/gs-007.pdf",
          wordUrl: "https://example.com/gs-007.docx",
          fieldChildType: "BIOMASS",
          createdTime: "2024-02-08 13:45:00"
        },
        {
          id: 8,
          methodCode: "CCER-008",
          dictCode: "CCER008",
          name: "森林碳汇项目方法学",
          fieldCode: "FOREST",
          fieldCodeName: "森林碳汇",
          industryCode: "FORESTRY",
          industryCodeName: "林业",
          certificationCriteria: "CCER",
          certificationCriteriaName: "CCER",
          statusCode: "0450000002",
          statusName: "已发布",
          sourceFileUrl: "https://example.com/ccer-008.pdf",
          pdfUrl: "https://example.com/ccer-008.pdf",
          wordUrl: "https://example.com/ccer-008.docx",
          fieldChildType: "HYDRO",
          createdTime: "2024-02-12 15:10:00"
        },
        {
          id: 9,
          methodCode: "VCS-009",
          dictCode: "VCS009",
          name: "交通电气化方法学",
          fieldCode: "TRANSPORT",
          fieldCodeName: "交通减排",
          industryCode: "TRANSPORTATION",
          industryCodeName: "交通运输",
          certificationCriteria: "VCS",
          certificationCriteriaName: "VCS",
          statusCode: "0450000003",
          statusName: "已下线",
          sourceFileUrl: "https://example.com/vcs-009.pdf",
          pdfUrl: "https://example.com/vcs-009.pdf",
          wordUrl: "https://example.com/vcs-009.docx",
          fieldChildType: "SOLAR",
          createdTime: "2024-02-15 10:25:00"
        },
        {
          id: 10,
          methodCode: "CDM-010",
          dictCode: "CDM010",
          name: "农业减排增汇方法学",
          fieldCode: "AGRICULTURE",
          fieldCodeName: "农业减排",
          industryCode: "AGRICULTURE",
          industryCodeName: "农业",
          certificationCriteria: "CDM",
          certificationCriteriaName: "CDM",
          statusCode: "0450000001",
          statusName: "未发布",
          sourceFileUrl: "https://example.com/cdm-010.pdf",
          pdfUrl: "https://example.com/cdm-010.pdf",
          wordUrl: "https://example.com/cdm-010.docx",
          fieldChildType: "WIND",
          createdTime: "2024-02-18 14:35:00"
        }
      ];
      
      this.nextId = 11; // 下一个ID
      console.log('模拟数据初始化完成，共', this.mockData.length, '条记录');
    },
    
    // 初始化字典数据
    async initDictionaryData() {
      try {
        console.log('开始初始化字典数据...');
        
        // 使用模拟数据
        this.initMockData();
        
        console.log('字典数据初始化完成');
      } catch (error) {
        console.error('初始化字典数据失败:', error);
        // 即使失败也尝试加载，使用默认数据
        this.initMockData();
      }
    },
    
    // 加载字典数据
    loadDictionaryData() {
      console.log('开始加载字典数据...');
      
      try {
        // 获取字典数据
        this.formatIndustry(getBusinessDict(this.$store));
        this.formatMethodStatus(getMethodStatusDict(this.$store));
        this.formatFieldCode(getProjectAreaDict(this.$store));
        this.Certification = this.formatStatus(getCertificationCriteriaDict(this.$store));
        this.fieldChildCodeList = this.formatStatus(getProjectTypeDict(this.$store));
        
        console.log('字典数据加载完成:', {
          industry: this.IndustryList.length,
          status: this.optionsOnlines.length,
          field: this.fieldCodeList.length,
          certification: this.Certification.length,
          projectType: this.fieldChildCodeList.length
        });
      } catch (error) {
        console.error('加载字典数据失败:', error);
      }
    },
    
    cellStyle({ row, column, rowIndex, columnIndex }) {},
    //判断是否发布，若发布了则修改样式
    editStyleChange(status) {
      return "afterSubmitEdit";
      // if (status == 1) {
      //   return "afterSubmitEdit";
      // } else {
      //   return "list-green-text";
      // }
    },
    publishStyleChange(status) {
      if (status == "0450000002") {
        return "afterSubmitPublish";
      } else {
        return "list-blue-text";
      }
    },
    offlineStyleChange(status) {
      if (status == "0450000002") {
        return "list-red-text";
      } else {
        return "afterSubmitOffline";
      }
    },
    onclickAdd() {
      this.dialogText = "添加方法学";
      this.methodForm["id"] = "";
      this.methodForm["dictCode"] = "";
      this.methodForm["fieldCode"] = "";
      this.methodForm["certificationCriteria"] = "";
      this.methodForm["industryCode"] = "";
      this.methodForm["methodCode"] = "";
      this.methodForm["name"] = "";
      this.methodForm["pdfUrl"] = "";
      this.methodForm["wordUrl"] = "";
      this.methodForm["fieldChildType"] = "";
      this.methodForm["sourceFileUrl"] = "";
      this.addMethodFormVisible = !this.addMethodFormVisible;
    
    },
    syncContentCarbonMethodology(data){
      let datas = {
        methodCode:data.methodCode,
        wordUrl:data.wordUrl,
      }
      synContentCarbonMethodology(datas).then(res=>{
        this.getList(1)
        this.$message.success("操作成功")
      })
    },
    onCancel(){
      this.addMethodFormVisible = false;
    },
    onclickSync(){
      this.$confirm('确定要同步方法学数据到Elasticsearch吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.syncToElasticsearch();
      }).catch(() => {
        this.$message.info('已取消同步');
      });
    },
    
    // 同步到Elasticsearch
    async syncToElasticsearch() {
      const loading = this.$loading({
        lock: true,
        text: '正在同步数据到Elasticsearch...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      
      try {
        // 模拟同步延迟
        await new Promise(resolve => setTimeout(resolve, 1500));
        
        // 模拟同步成功
        console.log('模拟同步到Elasticsearch成功，数据条数:', this.mockData.length);
        this.$message.success('同步成功！已同步 ' + this.mockData.length + ' 条方法学数据到Elasticsearch');
        
        // 刷新列表
        this.getList(this.current);
      } catch (error) {
        console.error('同步失败:', error);
        this.$message.error('同步失败: ' + error.message);
      } finally {
        loading.close();
      }
    },
    // 发布
    onClickPublish(row_id) {
      console.log('发布方法学:', row_id);
      
      // 查找并更新模拟数据
      const index = this.mockData.findIndex(item => item.id == row_id);
      if (index !== -1) {
        this.mockData[index].statusCode = "0450000002";
        this.mockData[index].statusName = "已发布";
        
        this.$message.success("发布成功");
        this.getList(this.current);
      } else {
        this.$message.error("未找到要发布的记录");
      }
    },
    // 删除
    onClickDelete(id) {
      var id = parseInt(id);
      this.$confirm("删除内容不可复原，请谨慎操作").then(() => {
        console.log('删除方法学:', id);
        
        // 从模拟数据中删除
        const index = this.mockData.findIndex(item => item.id == id);
        if (index !== -1) {
          this.mockData.splice(index, 1);
          this.$message.success("删除成功");
          this.getList(this.current);
        } else {
          this.$message.error("未找到要删除的记录");
        }
      });
    },
    onClickOffline(row_id) {
      console.log('下线方法学:', row_id);
      
      // 查找并更新模拟数据
      const index = this.mockData.findIndex(item => item.id == row_id);
      if (index !== -1) {
        this.mockData[index].statusCode = "0450000003";
        this.mockData[index].statusName = "已下线";
        
        this.$message.success("下线成功");
        this.getList(this.current);
      } else {
        this.$message.error("未找到要下线的记录");
      }
    },
    onClickSearch() {
      console.log('使用模拟数据进行搜索...');
      
      // 重置到第一页
      this.current = 1;
      
      // 调用getList方法，它会处理所有过滤逻辑
      this.getList(1);
      
      this.$message.success(`查询成功，共找到 ${this.total} 条记录`);
    },
    onEdit(row){
      this.dialogText = "修改方法学";
      this.addMethodFormVisible = true;
      let datas = {...row};
      this.methodForm = datas;
      console.log("this.methodForm",this.methodForm);
    },
    saveMothod(){
      // 表单验证
      if(!this.methodForm["methodCode"]) {
        return this.$message.error("请输入方法学编码!")
      }
      if(!this.methodForm["name"]) {
        return this.$message.error("请输入方法学名称!")
      }
      if(!this.methodForm["fieldCode"]) {
        return this.$message.error("请选择方法学领域!")
      }
      if(!this.methodForm["certificationCriteria"]) {
        return this.$message.error("请选择方法学核证标准!")
      }
      if(!this.methodForm["sourceFileUrl"]) {
        return this.$message.error("请输入方法学飞书pdf路径!")
      }
   
      let data = {...this.methodForm};
      
      // 清理数据
      for (let i in data) {
        if(data[i] == "--" || data[i] == ""){
          data[i] = null
        }
      }
      
      if(this.methodForm.id){//修改方法学
        console.log('修改方法学数据:', data);
        
        // 查找并更新模拟数据
        const index = this.mockData.findIndex(item => item.id == this.methodForm.id);
        if (index !== -1) {
          // 获取字典名称
          const fieldCodeItem = this.fieldCodeList.find(item => item.value === data.fieldCode);
          const fieldCodeName = fieldCodeItem ? fieldCodeItem.label : data.fieldCode;
          const industryCodeItem = this.IndustryList.find(item => item.value === data.industryCode);
          const industryCodeName = industryCodeItem ? industryCodeItem.label : data.industryCode;
          const certificationCriteriaItem = this.Certification.find(item => item.value === data.certificationCriteria);
          const certificationCriteriaName = certificationCriteriaItem ? certificationCriteriaItem.label : data.certificationCriteria;
          
          this.mockData[index] = {
            ...this.mockData[index],
            ...data,
            fieldCodeName,
            industryCodeName,
            certificationCriteriaName,
            pdfUrl: data.sourceFileUrl,
            statusName: this.statusName(data.statusCode || this.mockData[index].statusCode)
          };
          
          this.$message.success("修改成功！");
          this.addMethodFormVisible = false;
          this.getList(this.current); // 刷新列表
        } else {
          this.$message.error("未找到要修改的记录");
        }
      }else{//添加方法学
        console.log('添加方法学数据:', data);
        
        // 生成新ID
        const newId = this.nextId++;
        
        // 获取字典名称
        const fieldCodeItem = this.fieldCodeList.find(item => item.value === data.fieldCode);
        const fieldCodeName = fieldCodeItem ? fieldCodeItem.label : data.fieldCode;
        const industryCodeItem = this.IndustryList.find(item => item.value === data.industryCode);
        const industryCodeName = industryCodeItem ? industryCodeItem.label : data.industryCode;
        const certificationCriteriaItem = this.Certification.find(item => item.value === data.certificationCriteria);
        const certificationCriteriaName = certificationCriteriaItem ? certificationCriteriaItem.label : data.certificationCriteria;
        
        const newMethod = {
          id: newId,
          ...data,
          fieldCodeName,
          industryCodeName,
          certificationCriteriaName,
          pdfUrl: data.sourceFileUrl,
          statusCode: "0450000001", // 默认未发布
          statusName: "未发布",
          createdTime: new Date().toLocaleString('zh-CN', {
            year: 'numeric',
            month: '2-digit',
            day: '2-digit',
            hour: '2-digit',
            minute: '2-digit',
            second: '2-digit'
          }).replace(/\//g, '-')
        };
        
        this.mockData.push(newMethod);
        
        this.$message.success("添加成功！");
        this.addMethodFormVisible = false;
        this.getList(1); // 刷新列表，回到第一页
      }
    },
    
    goMethod(url) {
      openUrlInNewWindow(url);
    },
    //列表项点击事件，，跳转到对应url
    handleSizeChange(val) {
      this.pageSize = val;
      this.current = 1; // 改变页面大小时重置到第一页
      this.getList(1);
    },
    handleCurrentChange(val) {
      this.current = val;
      this.getList(val);
    },
    // 监听页面宽度变化，刷新表格
    handleResize() {
      if (this.infoList) this.$refs.visitChart.handleResize();
    },
    statusName(status) {
      if (status == "0450000002") {
        return "已发布";
      }
      if (status == "0450000001") {
        return "未发布";
      }
      if (status == "0450000003") {
        return "已下线";
      }
    },
    getList(page) {
      console.log('使用模拟数据获取列表...');
      
      // 使用模拟数据
      let filteredData = [...this.mockData];
      
      // 应用搜索过滤
      if (this.searchKeyWord) {
        const searchKey = this.searchKeyWord.toLowerCase();
        filteredData = filteredData.filter(item => 
          item.name.toLowerCase().includes(searchKey) ||
          item.methodCode.toLowerCase().includes(searchKey) ||
          item.dictCode.toLowerCase().includes(searchKey)
        );
      }
      
      // 应用状态过滤
      if (this.selectedStatus && this.selectedStatus.length > 0) {
        filteredData = filteredData.filter(item => 
          item.statusCode === this.selectedStatus[0]
        );
      }
      
      // 应用行业过滤
      if (this.selectedIndustry && this.selectedIndustry.length > 0) {
        filteredData = filteredData.filter(item => 
          item.industryCode === this.selectedIndustry[0]
        );
      }
      
      // 应用领域过滤
      if (this.selectedField && this.selectedField.length > 0) {
        filteredData = filteredData.filter(item => 
          item.fieldCode === this.selectedField[0]
        );
      }
      
      // 应用核证标准过滤
      if (this.selectedCertification && this.selectedCertification.length > 0) {
        filteredData = filteredData.filter(item => 
          item.certificationCriteria === this.selectedCertification[0]
        );
      }
      
      // 分页处理
      const currentPage = page || this.current || 1;
      const startIndex = (currentPage - 1) * this.pageSize;
      const endIndex = startIndex + this.pageSize;
      
      this.list = filteredData.slice(startIndex, endIndex);
      this.total = filteredData.length;
      this.current = currentPage;
      this.pageCount = Math.ceil(this.total / this.pageSize);
      
      // 处理显示数据
      this.list.forEach((v) => {
        v.statusName = this.statusName(v.statusCode);
        for (var i in v) {
          v[i] = v[i] ? v[i] : "--";
          if (v[i] == " ") {
            v[i] = "--";
          }
        }
      });
      
      console.log('模拟数据列表加载完成:', {
        total: this.total,
        current: this.current,
        pageSize: this.pageSize,
        listLength: this.list.length
      });
    },
    update() {
      const data = {
        asc: true,
        size: this.pageSize,
        // searchKey: this.searchKeyWord,
        industryCode: this.selectedIndustry[0],
        fieldCode: this.selectedField[0],
        certificationCriteria: this.selectedCertification[0],
        current: this.current,
        statusCode: this.selectedStatus[0],
      };
      if (this.searchKeyWord) {
        data["searchKey"] = this.searchKeyWord;
      }
      getEscarbonMethodologyByKeyword(data)
        .then((res) => {
          // this.list = res.data.records;
          this.list = res.data.data;
          this.total = res.data.total;
          this.current = res.data.current;
          this.pageCount = Math.ceil(parseInt(res.data.total) / this.pageSize);
          this.list.map((v) => {
            v.statusName = this.statusName(v.statusCode);
            for (var i in v) {
              v[i] = v[i] ? v[i] : "--";
            }
          });
        })
        .catch((errror) => {});
    },
    // checkbox start
    signCheckChange() {
      let allCheckedFlag = true;
      let allReset = true;
      this.list.forEach((item) => {
        if (item.checked == true) {
          allReset = false;
        } else {
          allCheckedFlag = false;
        }
      });
      if (allCheckedFlag || allReset) {
        this.indeterminateFlag = false;
        if (allCheckedFlag) {
          this.allchecked = true;
        } else {
          this.allchecked = false;
        }
      } else {
        this.indeterminateFlag = true;
      }
      this.reRender = !this.reRender;
    },
    //render-header方法
    renderCheckHeader(h, { column, $index }) {
      return h("span", {}, [
        h("el-checkbox", {
          props: {
            checked: this.allchecked,
            indeterminate: this.indeterminateFlag, //表头复选框状态
          },
          on: {
            change: this.updateAllSelected, // 选中事件
          },
        }),
      ]);
    },
    // 格式化标准字典
    formatStatus(data) {
      let list = [];
      data.map((v) => {
        let CertificationItem = {
          label: "",
        };
        if (v.name == "全部") {
          CertificationItem.label = v.name;
        } else {
          CertificationItem.value = v.value;
          CertificationItem.label = v.name;
        }
        list.push(CertificationItem);
      });
      return list;
    },
    // 格式化方法学状态字典
    formatMethodStatus(data) {
      data.map((v) => {
        let CertificationItem = {
          label: "",
        };
        if (v.name == "全部") {
          CertificationItem.label = v.name;
        } else {
          CertificationItem.value = v.value;
          CertificationItem.label = v.name;
        }
        this.optionsOnlines.push(CertificationItem);
      });
    },
    // 格式化领域字典
    formatFieldCode(data) {
      data.map((v) => {
        let CertificationItem = {
          label: "",
        };
        if (v.name == "全部") {
          CertificationItem.label = v.name;
        } else {
          CertificationItem.value = v.value;
          CertificationItem.label = v.name;
        }
        this.fieldCodeList.push(CertificationItem);
      });
    },
    // 格式化行业字典
    formatIndustry(data) {
      data.map((v) => {
        let CertificationItem = {
          label: "",
        };
        if (v.name == "全部") {
          CertificationItem.label = v.name;
        } else {
          CertificationItem.value = v.value;
          CertificationItem.label = v.name;
        }
        this.IndustryList.push(CertificationItem);
      });
    },
  
  },
  // checkbox end
  created() {
    // this.handleChangeVisitType();
  },
  async mounted() {
    // 先初始化字典数据
    await this.initDictionaryData();
    // 然后获取列表数据
    this.getList(1);
  },
};
</script>
<style lang="scss" scoped>
.root {
  background: #f2f5f7;
}

.divBox {
  margin: 20px;
  background: #ffffff;
  box-shadow: 0px 2px 8px 0px #eaf0f3;
  border-radius: 8px;
}

.container {
  margin: 20px 0px 20px 0px;
  display: flex;
  flex-direction: row;
}

.content-container {
  display: flex;
  flex-direction: column;
  width: 100%;
}

>>> .el-cascader .el-input .el-input__inner,
>>> .el-cascader .el-input.is-focus .el-input__inner {
  border-color: transparent;
}

.acea-row {
  /deep/.el-avatar--small {
    width: 22px;
    height: 22px;
    line-height: 22px;
  }
}

.checkTime {
  /deep/.el-radio__input {
    display: none;
  }
}

.ivu-pl-8 {
  margin-left: 8px;
  font-size: 14px;
}
/deep/ .el-dialog__header{
  background: #fcfcfc;
}
/deep/ .el-dialog__title{
  color: #000 !important;
}
.dashboard-console-visit {
  /deep/.el-card__header {
    padding: 14px 20px !important;
  }

  ul {
    li {
      list-style-type: none;
      margin-top: 12px;
    }
  }
}

.ivu-mb {
  margin-bottom: 10px;
}

.newsImg {
  width: 30px;
  height: 30px;
  border-radius: 4px;
}
.require {
  color: red;
  font-size: 16px;
  position: relative;
  right: 20px;
}
.table-text {
  position: relative;
  top: 10px;
  margin-left: 10px;
}
</style>